package compressFiles.server;

import com.intellij.openapi.util.text.*;
import compressFiles.common.*;
import jetbrains.buildServer.serverSide.*;
import org.jetbrains.annotations.*;

import java.util.*;

public class CompressFilesRunType extends RunType
{
    public CompressFilesRunType(@NotNull final RunTypeRegistry runTypeRegistry)
    {
        runTypeRegistry.registerRunType(this);
    }

    @NotNull
    @Override
    public String getType()
    {
        return PluginConstants.RunType;
    }

    @Override
    public String getDisplayName()
    {
        return PluginConstants.DisplayName;
    }

    @Override
    public String getDescription()
    {
        return PluginConstants.Description;
    }

    @Override
    public String describeParameters(@NotNull final Map<String, String> parameters)
    {
        StringBuilder sb = new StringBuilder();
        sb.append("Path:");
        sb.append(parameters.get("folderPath"));
        sb.append(" ");
        sb.append("Output:");
        sb.append(parameters.get("zipPath"));

        return sb.toString();
    }

    @Override
    public PropertiesProcessor getRunnerPropertiesProcessor()
    {
        return new PropertiesProcessor()
        {
            public Collection<InvalidProperty> process(Map<String, String> properties)
            {
                ArrayList<InvalidProperty> toReturn = new ArrayList<InvalidProperty>();
                if (!properties.containsKey("folderPath") || StringUtil.isEmpty(properties.get("folderPath")))
                    toReturn.add(new InvalidProperty("folderPath", "Please enter a path to compress"));

                if (!properties.containsKey("zipPath") || StringUtil.isEmpty(properties.get("zipPath")))
                    toReturn.add(new InvalidProperty("zipPath", "Please enter an output path"));

                return toReturn;
            }
        };
    }

    @Override
    public String getEditRunnerParamsJspFilePath()
    {
        return "editRunnerRunParameters.jsp";
    }

    @Override
    public String getViewRunnerParamsJspFilePath()
    {
        return "viewRunnerRunParameters.jsp";
    }

    @Override
    public Map<String, String> getDefaultRunnerProperties()
    {
        return null;
    }
}
